<!-- 下单列表 -->
<template>
	<view class="content" style="height: 100%;">
		<BaseNavBar :isnormarl="true" title="下单列表" :idx="1"/>
		<STabs :list="list" @getOrderData="getOrderData"></STabs>
		<view style="flex:1;height: 0;overflow-y: auto;">
			<orderpage :orderList0.sync="orderList0" :orderList1.sync="orderList1" :orderList2.sync="orderList2"
			:orderList3.sync="orderList3" @loadMoreData="loadMoreData" :status.sync="status"/>
		</view>
		<Tabbar />
	</view>
</template>

<script>
	import { getOrderList } from '../../api'
	import orderpage from "./orderPage.vue"
	export default {
		components: {
			orderpage
		},
		data() {
			return {
				list: [{
					name: '待发布',
				}, {
					name: '发单中',
				}, {
					name: '服务中'
				}, {
					name: '已完成'
				}],
				pageIndex: 1, 
				pageSize: 10,
				status: '待发布',
				orderList0: [],
				orderList1: [],
				orderList2: [],
				orderList3: [],
				end0: false,
				end1: false,
				end2: false,
				end3: false
			}
		},
		methods: {
			getOrderData(status) {
				console.log('getOrderData', status)
				this.status = status
			},
			async loadMoreData() {
				console.log('5555')
				if(this.status == '待发布' && this.end0) {
					return
				} else if(this.status == '发单中' && this.end1) {
					return
				} else if(this.status == '服务中' && this.end2) {
					return
				} else if(this.status == '已结束' && this.end3) {
					return
				} else {
					let data = {
						pageIndex: this.pageIndex,
					    pageSize: this.pageSize,
					    queryBean: {
					        status: this.status
					    }
					}
					await this.orderDataFn(data)
				}
			},
			async orderDataFn(data) {
				console.log('999')
				let pageIndex = data.pageIndex
				let status = data.queryBean.status
				let res = await getOrderList(data)
				console.log('666', res)
				if(res.status == 200 && res.data.records.length) {
					if(status == '待发布') {
						this.orderList0.push(...res.data.records)
					} else if(status == '发单中') {
						this.orderList1.push(...res.data.records)
					} else if(status == '服务中') {
						this.orderList2.push(...res.data.records)
					} else if(status == '已结束') {
						this.orderList3.push(...res.data.records)
					}
				}
				if(res.status == 200) {
					if((pageIndex + 1) * res.data.size < res.data.total) {
						pageIndex++
						if(status == '待发布') {
							this.pageIndex0 = pageIndex
						} else if(status == '发单中') {
							this.pageIndex1 = pageIndex
						} else if(status == '服务中') {
							this.pageIndex2 = pageIndex
						} else if(status == '已结束') {
							this.pageIndex3 = pageIndex
						}
					} else {
						if(status == '待发布') {
							this.end0 = true
						} else if(status == '发单中') {
							this.end1 = true
						} else if(status == '服务中') {
							this.end2 = true
						} else if(status == '已结束') {
							this.end3 = true
						}
					}
				}
			}
		},
		onLoad() {
			this.list.forEach(async (item, index) => {
				let data = {
					pageIndex: 0,
				    pageSize: 10,
				    queryBean: {
				        status: item.name
				    }
				}
				await this.orderDataFn(data)
			})
		},
		onShow() {
			uni.hideTabBar({
				animation: false
			})
		}
	}
</script>

<style>

</style>
